package com.ys.service.administration.impl;

import com.alibaba.fastjson.JSON;
import com.ys.dto.AddDto;
import com.ys.entity.administration.AdmSignetManage;
import com.ys.mapper.administration.AdmSignetManageMapper;
import com.ys.service.administration.AdmSignetManageService;
import com.ys.util.BidUtil;
import com.ys.util.shiro.ShiroUtils;
import com.ys.vo.R;
import lombok.Synchronized;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service("admSignetManageService")
public class AdmSignetManageServiceImpl implements AdmSignetManageService {
	private static final Logger logger = LoggerFactory.getLogger(AdmSignetManageServiceImpl.class);

	@Autowired
	private AdmSignetManageMapper admSignetManageMapper;


	/**
	 * 新增
	 */
	@Override
	public R add(Map<String, Object> params) {
		AdmSignetManage admSignetManage = JSON.parseObject(JSON.toJSONString(params), AdmSignetManage.class);
		admSignetManage.setStatus(1);
		admSignetManage.setUpdateUser(ShiroUtils.getUserId());//用户角色id
		String code = "YZ0001";
		AdmSignetManage entityMax = new AdmSignetManage().setOrderby("A.Code DESC").queryFirst();
		if(entityMax!=null){
			code = "YZ" + BidUtil.parseIntToFourLen(Integer.parseInt(entityMax.getCode().replace("YZ", "")) + 1);
		}
		admSignetManage.setCode(code);
		int result = admSignetManageMapper.insert(admSignetManage);

		return R.ok(AddDto.gotoEdit("/web/administration/webAdmSignetManageController/toEdit?id=" + admSignetManage.getId()));
	}

	/**
	 * 修改
	 */
	@Override
	public R update(Map<String, Object> params) {
		AdmSignetManage admSignetManage = JSON.parseObject(JSON.toJSONString(params), AdmSignetManage.class);
		admSignetManage.setStatus(1);
		int result = admSignetManageMapper.update(admSignetManage);
		//return R.ok(AddDto.gotoEdit("/web/administration/webAdmSignetManageController/toEdit?id=" + admSignetManage.getId()));
		return R.ok(AddDto.noAction());
	}


	//删除
	@Override
	public int del(long id){
		return admSignetManageMapper.deleteTrue(id);
	}


}
